package org.feng.navigation.rest.gatewayimpl.tianxing;

import org.feng.navigation.common.util.GsonUtil;
import org.feng.navigation.domain.rpc.common.Router;
import org.feng.navigation.domain.rpc.tianxing.domainobject.allnews.TianXingAllNewsRequest;
import org.feng.navigation.rest.gatewayimpl.RouterFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 天行请求体转换组件
 *
 * @version v1.0
 * @author: junzi
 * @date: 2023年02月05日 17时15分
 */
@Component
public class TianXingRequestConvertComponent extends RouterFactory {

    @Router(value = TianXingAllNewsRequest.class, desc = "天行数据-分类新闻接口请求体转换")
    protected MultiValueMap<String, Object> convertAllNewsRequest(TianXingAllNewsRequest request) {
        String json = GsonUtil.toJson(request);
        Map<String, Object> stringObjectMap = GsonUtil.parseToObjectMap(json);
        Map<String, List<Object>> multiMap = new HashMap<>(16);
        stringObjectMap.forEach((key, value) -> {
            ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(value);
            multiMap.put(key, arrayList);
        });
        return new LinkedMultiValueMap<>(multiMap);
    }
}
